﻿using SelfMadeMillionaire.Core.Entities;
using SelfMadeMillionaire.Web.Infrastructure.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SelfMadeMillionaire.Web.Infrastructure.ViewModels.Newsletters
{
	public class NewsletterEditViewModel
	{
		public int ID { get; set; }

		[Required]
		[StringLength(100)]
		public string Title { get; set; }
		[Required]
		[DisplayName("Symbol(s)")]
		[StringLength(100)]
		public string Symbols { get; set; }
		[Required]
		public byte Letter { get; set; }
		[Required]
		[DisplayName("Issue Type")]
		public int IssueType { get; set; }

		[DisplayName("Min. Access Level")]
		public byte MinAccessLevel { get; set; }

		public string PdfFileName { get; set; }

		public SelectList IssueTypes { get; set; }
		public SelectList ProductTypes { get; set; }
        public List<int> SelectedProducts { get; set; }
		public SelectList AccessLevels { get; set; }

		public DateTime Date { get; set; }

		[RequiredIf("PdfFileName", null)]
		[DisplayName("File")]
		public HttpPostedFileBase PdfFile { get; set; }

	}

    public class NewsletterPublicEditViewModel
    {
        public Newsletter Item { get; set; }
        public IEnumerable<Newsletter> OtherIssue { get; set; }

        public NewsletterPublicEditViewModel()
        {
            OtherIssue = new List<Newsletter>();
        }
    }

    public class NewslettersBySymbolViewModel
    {
        public int NewsletterId { get; set; }
        public string Symbol { get; set; }
        public string NewsletterSymbols { get; set; }
        public IEnumerable<Newsletter> BySymbolIssue { get; set; }

        public SelectList NewsletterSymbolsList
        {
            get
            {
                List<SelectListItem> retList = new List<SelectListItem>();
                string[] arrSymbols = NewsletterSymbols.Split(new string[] { ", " }, StringSplitOptions.None);
                foreach(string item in arrSymbols)
                {
                    retList.Add(new SelectListItem() { Text = item, Value = item });
                }

                return new SelectList(retList, "Value", "Text");
            }
        }
    }
}
